package com.museum.guide.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.museum.guide.common.result.Result;
import com.museum.guide.entity.Feedback;
import com.museum.guide.service.FeedbackService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Resource
    private FeedbackService feedbackService;

    /**
     * 分页查询反馈信息
     */
    @GetMapping("/page")
    public Result<Page<Feedback>> page(
            Page<Feedback> page,
            String title,
            String type,
            String status,
            Long userId) {
        return Result.success(feedbackService.page(page, title, type, status, userId));
    }

    /**
     * 新增反馈
     */
    @PostMapping("/add")
    public Result<Void> save(@RequestBody @Valid Feedback feedback) {
        feedbackService.saveFeedback(feedback);
        return Result.success();
    }

    /**
     * 更新反馈信息
     */
    @PostMapping("/update")
    public Result<Void> update(@RequestBody @Valid Feedback feedback) {
        feedbackService.updateFeedback(feedback);
        return Result.success();
    }

    /**
     * 删除反馈
     */
    @DeleteMapping("/removeById")
    public Result<Void> remove(Long id) {
        feedbackService.removeFeedback(id);
        return Result.success();
    }

    /**
     * 回复反馈
     */
    @PostMapping("/reply")
    public Result<Void> reply(
            @RequestParam Long id,
            @RequestParam String reply,
            @RequestParam Long replyUserId) {
        feedbackService.replyFeedback(id, reply, replyUserId);
        return Result.success();
    }
}